package com.lin.cms.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.lin.cms.domain.Content;

public class ContentValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return Content.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contentId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "channelId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "typeId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "siteId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sortDate", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "topLevel", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "hasTitleImg", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isRecommend", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "status", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "viewsDay", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "commentsDay", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "downloadsDay", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "upsDay", "required");
	}

}
